<?php
class Top_visits_week extends Widget
{

	function run() {
    	
    	$this->ci->load->model("Node_Model", "Nodes");
    	
    	$data = array();
    	
    	$cache_time = intval($this->ci->settings->item("_site_cache_nodes_time"));
		
		$meta_key = $this->ci->Nodes->_countersName['week'];
    	$node_params = array(
			"order" => array("meta.$meta_key" => "INTEGER desc")
		);
    	$nodes = $this->ci->mp_cache->model("Nodes", "get", array($node_params), $cache_time);
		
		$nodes_process = array();
		
		foreach($nodes as $node){
			$node->categories = $this->ci->mp_cache->model("Nodes", "getCategories", array($node->id), $cache_time);
			$metas = $this->ci->mp_cache->model("Nodes", "getMeta", array($node->id), $cache_time);
			
			$node->metas = array();
			foreach($metas as $meta){
				if($meta->meta_key == $meta_key){
					$node->metas["counter_week"] =  $meta->meta_value;
				}
				$node->metas[$meta->meta_key] = $meta->meta_value;
			}
			
			array_push($nodes_process, $node);
		}
		
		$data['nodes'] = $nodes_process;
		
		$this->template->load("widgets/top_visits_week", $data);
        //$this->render('top_visits_total', $data);
    }
} 
?>